<template lang="zh_CN">
<div class="WoDe">
  <div class="WoDe-content" @click="goLogin">
    <div class="avatar">
      <u-avatar size="70" :src="personalInfo.headImage"></u-avatar>
    </div>
    <div class="WoDe-right" v-if="token">
      <div class="name">{{personalInfo.nickName || '暂无昵称' }}</div>
      <div class="f28">
        <div class="vip">
          <div class="img" v-if="personalInfo.levelName">
            <img :src="require('./static/vip-icon.png')"/>
          </div>
          <span>{{personalInfo.levelName || '普通用户'}}</span>
        </div>
        <span>{{personalInfo.phone}}</span>
      </div>
    </div>
    <div class="WoDe-right no-login" v-else>未登录</div>
    <div class="icon">
      <u-icon name="arrow-right" color="#333" size="24"></u-icon>
    </div>
  </div>

  <div class="card" v-if="token">
    <u-grid :border="true" col="4">
      <u-grid-item>
        <div class="number">{{personalInfo.productCollectNum}}</div>
        <div class="title">收藏</div>
      </u-grid-item>
      <!-- <u-line direction="col" length="24" cloor="#d8d8d8"></u-line> -->
      <u-grid-item>
        <div class="number">{{personalInfo.redPacketMoney}}</div>
        <div class="title">红包</div>
      </u-grid-item>
      <!-- <u-line direction="col" length="24" cloor="#d8d8d8"></u-line> -->
      <u-grid-item>
        <div class="number">{{personalInfo.integralNum}}</div>
        <div class="title">积分</div>
      </u-grid-item>
      <!-- <u-line direction="col" length="24" cloor="#d8d8d8"></u-line> -->
      <u-grid-item>
        <div class="number">{{personalInfo.couponMoney}}</div>
        <div class="title">优惠券</div>
      </u-grid-item>
    </u-grid>
  </div>

  <div class="card">
    <u-cell title="我的订单" value="全部" :isLink="true" :border="false" size="large" url="/subPackages/WoDe/orderList"></u-cell>
    <u-grid :border="false" col="4">
      <u-grid-item @click="goOrder(1)">
        <image :src="require('./static/daifukuan-icon.png')">
        </image>
        <div class="title">待付款</div>
      </u-grid-item>
      <u-grid-item @click="goOrder(2)">
        <image :src="require('./static/daifahuo-icon.png')">
        </image>
        <div class="title">待发货</div>
      </u-grid-item>
      <u-grid-item @click="goOrder(3)">
        <image :src="require('./static/daishouhuo-icon.png')">
        </image>
        <div class="title">待收货</div>
      </u-grid-item>
      <u-grid-item @click="goOrder(8)">
        <image :src="require('./static/yiquxiao-icon.png')">
        </image>
        <div class="title">已取消</div>
      </u-grid-item>
    </u-grid>
  </div>

  <div class="card">
    <u-cell title="其他服务" :border="false" size="large"></u-cell>
    <u-grid :border="false" col="4">
      <u-grid-item @click="goHelp">
        <img :src="require('./static/help-icon.png')"/>
        <div class="title">帮助中心</div>
      </u-grid-item>
      <u-grid-item v-if="token" @click="goAddr">
        <img :src="require('./static/address-icon.png')"/>
        <div class="title">地址管理</div>
      </u-grid-item>
      <!-- <u-grid-item>
        <img :src="require('./static/guanyuwomen-icon.png')"/>
        <div class="title">关于我们</div>
      </u-grid-item> -->
    </u-grid>
  </div>
</div>
</template>

<script>
import auth from "../../api/auth";

export default {
  data() {
    return {
      token:'',
      personalInfo: {},
    };
  },
  onShow() {
    this.token = uni.getStorageSync("AUTH_TOKEN");
    if(this.token) {
      this.memberGetUserInfo()
      uni.stopPullDownRefresh();
    }
  },
  onPullDownRefresh() {
    this.token = uni.getStorageSync("AUTH_TOKEN");
    if(this.token) {
      this.memberGetUserInfo()
      uni.stopPullDownRefresh();
    }
  },
  methods: {
    // 获取我的页面信息
    async memberGetUserInfo() {
      let res = await auth.memberGetUserInfo();
      this.personalInfo = { ...res };
      uni.setStorageSync('_PHONE_', res.phone)
      uni.setStorageSync('_NICK_NAME_', res.nickName)
      uni.setStorageSync('_HEAD_IMAGE_', res.headImage)
    },
    goLogin() {
      if(this.token) {
        uni.navigateTo({url:'/subPackages/SheZhi/index'})
      } else {
        uni.reLaunch({url: '/subPackages/Login/index'})
      }
    },
    goOrder(active) {
      uni.navigateTo({url:'/subPackages/WoDe/orderList?active=' + active})
    },
    goAddr() {
      uni.navigateTo({url:'/subPackages/WoDe/address'})
    },
    goHelp() {
      uni.navigateTo({url:'/subPackages/SheZhi/HelpCenter'})
    }
  },
};
</script>

<style lang="scss">
.WoDe {
  height: 100%;
  background-color: #f8fafb;
  background-image: url("https://hlgz-mall.oss-cn-hangzhou.aliyuncs.com/basic/32/9c89d39b9fbb4c2e87b696a9ef7bd49e.png");
  background-repeat: no-repeat;
  background-size: 100%;
  background-position: 0% 0%;
  padding: 0 32rpx;
  .WoDe-content {
    display: flex;
    align-items: center;
    padding: 150rpx 0 24px;
    color: #fff;
    font-size: 36rpx;
    .avatar {
      border: 4rpx solid #fff;
      border-radius: 50%;
      margin-right: 24rpx;
    }
    .WoDe-right {
      display: flex;
      flex-direction: column;
      justify-content: center;
      flex: 1;
      .name {
        font-size: 32rpx;
        font-weight: 500;
        color: #222;
      }
      .f28 {
        font-size: 20rpx;
        color: #333;
        display: flex;
        margin-top: 12rpx;
        .vip {
          display: flex;
          width: 128rpx;
          font-size: 20rpx;
          text-align: center;
          background: #F4D2A8;
          margin-right: 16rpx;
          border-radius: 12rpx 4rpx 4rpx 4rpx;
          .img {
            width: 40rpx;
            height: 32rpx;
            display: flex;
            justify-content: center;
            align-items: center;
            background: linear-gradient( 153deg, #F6EFE5 0%, #F8E5D3 100%);
            border-radius: 12rpx 0rpx 12rpx 4rpx;
            img {
              width: 24rpx;
              height: 24rpx;
            }
          }
          span {
            display: inline-block;
            width: 100%;
            text-align: center;
            color: #7F4D27;
          }
        }
      }
      .icon {
        width: 28rpx;
        height: 28rpx;
      }
    }
    .no-login {
      color: #333;
    }
  }

  .card {
    padding: 20rpx;
    box-sizing: border-box;
    background: #fff;
    border-radius: 16rpx;
    margin-bottom: 20rpx;
    image {
      position: relative;
      width: 72rpx;
      height: 72rpx;
    }
    .number {
      font-size: 44rpx;
      font-weight: 500;
    }
    .title {
      color: #bdc2c7;
      font-size: 24rpx;
      line-height: 36rpx;
    }
  }

}
</style>
